#include <GameEngine/UnitTest/unit_test.h>

#include <GameEngine/Maps/displacement.h>


#ifdef GAMEENGINE_NAMESPACES
namespace GameEngine {
#endif


//! Launch the unit tests on graph lists
/*!
 @return True if all unit tests on graph lists were
         succesful, false otherwise
 */
bool UnitTest::test_maps_displacement_iterator_functions() {
	bool res = true;

	// Get number of bytes
	MemoryManager::BytesCount bytes = MemoryManager::instance()->bytes();

	// Create displacement types
	GameEngine::Displacement::DisplacementTypes types;

	{{
		// Test iterator
		int index = 0;
		for ( GameEngine::DisplacementTypesIterator it(types); it.more(); it.next() ) {
			if ( index == 0 ) {
				res &= UNIT_TEST_ERROR( "[Displacement::Iterator] Current function", ( it.cur() == GameEngine::Displacement::Inaccessible ) );
			}
			else {
				// There should only be one index
				res &= UNIT_TEST_ERROR( "[Displacement::Iterator] Current function", false );
			}
			++index;
		}
	}}

	// Add movement types
	types |= GameEngine::Displacement::Walkable;
	types |= GameEngine::Displacement::Flyable;

	{{
		// Test iterator
		int index = 0;
		for ( GameEngine::DisplacementTypesIterator it(types); it.more(); it.next() ) {
			if ( index == 0 ) {
				res &= UNIT_TEST_ERROR( "[Displacement::Iterator] Current function", ( it.cur() == GameEngine::Displacement::Walkable ) );
			}
			else if ( index == 1 ) {
				res &= UNIT_TEST_ERROR( "[Displacement::Iterator] Current function", ( it.cur() == GameEngine::Displacement::Flyable ) );
			}
			else {
				// There should only be two indexes
				res &= UNIT_TEST_ERROR( "[Displacement::Iterator] Current function", false );
			}
			++index;
		}
	}}

	// Get number of bytes
	res &= UNIT_TEST_ERROR( "[Displacement::Iterator] Test memory leak", ( bytes == MemoryManager::instance()->bytes() ));

	// Return result
	return res;
}


#ifdef GAMEENGINE_NAMESPACES
} // namespace GameEngine
#endif
